package com.hyt.it.ogt.opertaion.track.executor;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 朱振宇
 * @since 2022/10/14
 */
public class OperationTrackExecutorThreadFactory implements ThreadFactory {

    private final AtomicInteger threadNo = new AtomicInteger(0);

    private final String threadName;

    public OperationTrackExecutorThreadFactory(String threadName) {
        this.threadName = !threadName.endsWith(".")? threadName + ".": threadName;
    }

    @Override
    public Thread newThread(Runnable r) {
        String tName = threadName + threadNo.getAndIncrement();
        Thread thread = new Thread(r, tName);
        thread.setDaemon(true);
        return thread;
    }
}
